import Mock from 'mockjs'

// Mock 楼盘基本信息
//  /api/project?project_id=123
const projectInfo = Mock.mock(/\/api\/project(\?.*)?$/, 'get', (options: any) => {
  // 解析URL参数
  const url = new URL(options.url, 'http://localhost')
  const projectId = url.searchParams.get('project_id')

  console.log('Mock projectInfo called with projectId:', projectId)

  // 根据project_id生成不同的数据，如果没有project_id也返回默认数据
  const seed = projectId ? projectId.charCodeAt(0) : 1

  // 每次请求时重新定义数据生成逻辑
  const titles = ['碧桂园天越府南苑', '万科金域蓝湾', '恒大御景湾', '绿城桂花城', '保利香槟国际']

  const subtitles = ['赣榆区赣榆', '浦东新区陆家嘴', '天河区珠江新城', '西湖区文三路', '朝阳区国贸']

  // 直接根据seed选择数据，而不是使用Mock.Random.extend
  const projectTitle = titles[seed % titles.length]
  const projectSubtitle = subtitles[seed % subtitles.length]

  return {
    code: 200,
    message: 'success',
    data: {
      title: projectTitle,
      subtitle: projectSubtitle,
      description: `在售均价${Mock.Random.integer(10000, 30000)}元/㎡`,
      totalCount: Mock.Random.integer(100, 1670),

      // 楼盘列表
      buildingList: [
        {
          id: 1,
          name: '1号楼(10套)'
        },
        {
          id: 2,
          name: '2号楼(195套)'
        },
        {
          id: 3,
          name: '3号楼(1套)'
        }
      ]
    }
  }
})

export default {
  projectInfo
}
